package com.dingwen.treasure.kettle.task;

import com.dingwen.treasure.kettle.enums.FileTypeEnum;
import com.dingwen.treasure.kettle.constant.TaskConstant;
import lombok.extern.slf4j.Slf4j;
import org.quartz.Job;
import org.quartz.JobDataMap;
import org.quartz.JobDetail;
import org.quartz.JobExecutionContext;

/**
 * 　AbstractTask
 * 　@author dingwen
 * 　@date 2022/5/11$
 */
@Slf4j
public abstract class AbstractTask implements Job {
    @Override
    public void execute(JobExecutionContext jobExecutionContext) {
        addExecuteStartTime(jobExecutionContext);
        //*********************/
        JobDetail jobDetail = jobExecutionContext.getJobDetail();
        JobDataMap jobDataMap = jobDetail.getJobDataMap();
        log.info("定时任务：{}执行", jobDetail.getKey().getName());
        exactExecution(
                (FileTypeEnum) jobDataMap.get(TaskConstant.FILE_TYPE),
                jobDataMap.get(TaskConstant.FULL_FILE_NAME).toString()
        );
        //*********************//
    }

    private void addExecuteStartTime(JobExecutionContext jobExecutionContext) {
        jobExecutionContext.getJobDetail()
                .getJobDataMap()
                .put(TaskConstant.EXECUTE_START_TIME, System.currentTimeMillis());
    }


    /**
     * 精确执行
     *
     * @param fileType 文件类型
     * @param fullFileName   文件全路径
     */
    protected abstract void exactExecution(FileTypeEnum fileType, String fullFileName);
}
